package xyc.sjxy.service.impl;

import xyc.sjxy.dao.UserDao;
import xyc.sjxy.dao.impl.UserDaoImpl;
import xyc.sjxy.pojo.Users;
import xyc.sjxy.service.UserServices;

import java.sql.SQLException;
import java.util.List;

public class UserServicesImpl implements UserServices {
    private UserDao userDao = new UserDaoImpl();
    @Override
    public Users getById(Integer id) throws SQLException {
        return userDao.findById(id);
    }

    @Override
    public Boolean validate(String username, String password) throws SQLException {
        Users user = userDao.findByUsername(username, password);
        if (user != null) {
            return true;
        }
        return false;
    }

    @Override
    public List<Users> getAll() {
        return userDao.findAll();
    }

    @Override
    public int add(Users users) throws SQLException {
        return userDao.insert(users);
    }

    @Override
    public int edit(Users users) throws SQLException {
        return userDao.update(users);
    }
    public int editPwd( Users users) throws SQLException {
        return userDao.updatePwd(users);
    }

    public int edit_pic(Users users) throws SQLException {
        return userDao.update_pic(users);
    }

    @Override
    public int del(Integer id) {
        return userDao.delete(id);
    }

    @Override
    public Users getByUserName(String username) throws SQLException {
        return  userDao.findByUsername(username);
    }
}